package com.zzx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzx.common.domain.CommonResult;
import com.zzx.mapper.GoodsMapper;
import com.zzx.pojo.Goods;
import com.zzx.service.IGoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Author ZZX
 * @Date 2023/10/3 12:45
 */
@Service
public class GoodsServiceImpl implements IGoodsService
{
    @Resource
    GoodsMapper goodsMapper;

    @Override
    public CommonResult getGoodsById(Integer goodsId)
    {
        return CommonResult.ok().data("goods", goodsMapper.selectById(goodsId));
    }

    @Override
    public CommonResult getGoodsList()
    {
        return CommonResult.ok().data("goodsList", goodsMapper.selectList(new QueryWrapper<Goods>().orderByDesc("id")));
    }

    @Override
    public CommonResult editGoodsNum(Goods goods)
    {
        return CommonResult.ok().data("编辑后的数量", goodsMapper.updateById(goods));
    }
}